package org.dromara.crawler.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.crawler.domain.KnowledgeTemplate;
import org.dromara.crawler.domain.TargetEvent;
import org.dromara.crawler.mapper.TargetEventMapper;
import org.dromara.crawler.service.TargetEventService;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class TargetEventServiceImpl extends ServiceImpl<TargetEventMapper, TargetEvent> implements TargetEventService {


    @Override
    public boolean deleteTargetEvent(Long id) {

        return this.removeById(id);
    }

    @Override
    public IPage<TargetEvent> queryByPage(TargetEvent targetEvent, PageQuery pageQuery) {
        LambdaQueryWrapper<TargetEvent> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(ObjectUtil.isNotEmpty(targetEvent.getEventFirstLevel()), TargetEvent::getEventFirstLevel, targetEvent.getEventFirstLevel());
        wrapper.like(ObjectUtil.isNotEmpty(targetEvent.getEventSecondLevel()), TargetEvent::getEventSecondLevel, targetEvent.getEventSecondLevel());
        wrapper.like(ObjectUtil.isNotEmpty(targetEvent.getKeywords()), TargetEvent::getKeywords, targetEvent.getKeywords());
        wrapper.eq(ObjectUtil.isNotEmpty(targetEvent.getStatus()), TargetEvent::getStatus, targetEvent.getStatus());
        wrapper.orderByDesc(TargetEvent::getCreateTime);
        return baseMapper.selectPage(pageQuery.build(),wrapper);
    }

    @Override
    public Boolean addEntity(TargetEvent targetEvent) {
        return null;
    }
}
